#include <iostream>
#include "fma_src.h"
using namespace std;

const int USEC = 1000000;
const int MSEC = 1000;

uint64_t GetTimeUs() {
  struct timespec ts = {0, 0};
  if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
    return 0;
  }
  // USECS_IN_SEC *NSECS_IN_USEC;
  auto ret_val = static_cast<uint64_t>((ts.tv_sec * USEC) + (ts.tv_nsec / MSEC));
  return ret_val;
}

int main() {
  auto start = GetTimeUs();
  size_t loop_count = 1000000000;
  test_fma_flops(loop_count);
  auto end = GetTimeUs();
  auto exec_time = (end - start) / 1000000.f;
  cout << "fma loop count:[" << loop_count * 15 << "] exec time is [" << exec_time << "]s" << endl;
  // exec instrustions * float num per instruction
  cout << "FMA in ARM GFLOPS is " << loop_count * 15 * 8 / exec_time / 1000000000 << "GFLOPS" << endl;
  cout << "无论是ARM还是Intel，FMA指令一般可以达到CPU理论性得96%(+-)使用率" << endl;
  return 0;
}